﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VisionApp.Startup.ViewModels;
using VisionApp.UserManager.Service;

namespace VisionApp.Startup.Views
{
    /// <summary>
    /// LoginView.xaml 的交互逻辑
    /// </summary>
    public partial class LoginView
    {
        private readonly IUserManagerService userManagerService;
        public event EventHandler<bool>? LoginSuccess;
        private LoginViewModel? ViewModel => DataContext as LoginViewModel;
        public LoginView(/*IUserManagerService userManagerService*/)
        {
            InitializeComponent();
            this.userManagerService = userManagerService;
            //BtnLogin.IsEnabled = false;
            ViewModel.LoginCompleted += ViewModel_LoginCompleted;
        }

        private void ViewModel_LoginCompleted(bool obj)
        {
            // 登录成功，关闭窗口
            if (obj) { 
            this.Close();
            }
            else
            {
                MessageBox.Show("登录失败","错误");
            }
        }

        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
           // var userName = UserNameTextBox.Text;
           // var password = PasswordBox.Password;
           // // 验证数据
           // if (string.IsNullOrEmpty(userName))
           // {
           //     Info.Content = "用户名不能为空";
           //     return;
           // }
           // if (string.IsNullOrEmpty(password))
           // {
           //     Info.Content = "密码不能为空";
           //     return;
           // }
           // var result= userManagerService.Login(userName, password);
           //if (result)  Info.Content = "登录成功";           
           // LoginSuccess?.Invoke(this, result);
           // this.Close();
        }

        private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            ViewModel.Password= PasswordBox.Password;
        }
    }
}
